<template>
  <div class="earthds_box">
    <DSheader></DSheader>
    <div class="earthds_earth">
      <DSContainer></DSContainer>
    </div>
    <DSStatusBar></DSStatusBar>
    <TooltipCom v-if="currentDialog == 'submit'" :content="'列表中有正在编辑的对象尚未提交，是否提交'" :title="'提交'"
      :isVisible="true" @close="currentDialog = undefined" @confirm="submitConfirm" />
  </div>

</template>

<script lang="ts" setup>
import DSContainer from './views/rts-container.vue';
import DSheader from './views/rts-header.vue';
import DSStatusBar from './views/rts-statusBar.vue';
import { ref, onMounted, onUnmounted } from 'vue';
import TooltipCom from "@/components/common/TooltipCom.vue";
import { getProjectManager } from "@/scripts/getProjectManager";

const objm = getProjectManager();
const cimrtsManager = objm.cimrtsManager
const modelser2Manager = objm.modelser2Manager

const currentDialog = ref<undefined | string>(undefined);

const handleBeforeUnload = (event: any) => {
  const c = objm.cimrtsSceneTreeWrapper?.json.root.children
  const m = objm.modelser2SceneTreeWrapper?.json.root.children

  if ((c && c.length) || (m && m.length)) {
    currentDialog.value = 'submit';
    event.preventDefault();
    event.returnValue = "";
  }
}

// 提交 确定按钮
const submitConfirm = async () => {
  const c = objm.cimrtsSceneTreeWrapper?.json.root.children
  const m = objm.modelser2SceneTreeWrapper?.json.root.children
  console.log(c);
  
  if (c && c.length) {
    await cimrtsManager.submitEditorMultioperation()
  }
  if (m && m.length) {
    await modelser2Manager.createClipTask()
  }

  currentDialog.value = undefined
}

onMounted(() => {
  window.addEventListener('beforeunload', handleBeforeUnload);

})

onUnmounted(() => {
  window.removeEventListener('beforeunload', handleBeforeUnload);
})



</script>

<style>
.earthds_box {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.earthds_earth {
  width: 100%;
  height: calc(100% - 50px);
}
</style>
